import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/hire/api/hireApi.dart';
import 'package:honeypotflutter/modules/hire/views/hire_rent_rent_button.dart';
import 'package:honeypotflutter/modules/hire/views/hire_rent_rent_day.dart';
import 'package:honeypotflutter/modules/hire/views/hire_rent_rent_header.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_future.dart';
import 'package:honeypotflutter/public/views/public_scrollView.dart';
import '../../models/hire_rent_rent_model.dart';
import '../../views/hire_rent_rent_box.dart';
import 'logic.dart';

class HireRentRentPage extends StatefulWidget {
  const HireRentRentPage({Key? key}) : super(key: key);

  @override
  State<HireRentRentPage> createState() => _HireRentRentPageState();
}

class _HireRentRentPageState extends State<HireRentRentPage> {
  final HireRentRentLogic logic = Get.put(HireRentRentLogic());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    logic.itemModel = Get.arguments;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: HLAppBar(navigationTitle: "租用"),
      body: HLFuture<HireRentRentModel>(
          future: HireApi.priceInfo(logic.itemModel.deviceId),
          snap: (AsyncSnapshot<HireRentRentModel> snap) {
            if (!snap.hasData) {
              return null;
            }
            logic.priceModel = snap.data!;
            return HLScrollView(
              padding: EdgeInsets.all(12),
              children: [
                HireRentRentHeader(),
                HireRentRentBox(),
                HireRentRentDayPage(),
              ],
            );
          }),
      bottomNavigationBar: Obx(() => HireRentRentButton(
            price: logic.countPrice.value,
            rentAction: logic.sureRent,
          )),
    );
  }

  @override
  void dispose() {
    Get.delete<HireRentRentLogic>();
    super.dispose();
  }
}
